<?php

namespace App\Models;

class UserGrade extends Model
{
    protected $table = 'yf_user_grade';
    protected $primaryKey = 'user_grade_id';
    public $timestamps = false;
    protected $guarded = ['user_grade_id'];

    public static function upgrade(UserResource $resource, YfUserInfo $yfUserInfo) : bool
    {
        $gradeId = self::where('user_grade_demand', '>=', $resource->user_growth)
            ->oldest('user_grade_demand')
            ->value('user_grade_id') ?: 1;

        return $yfUserInfo->update(['user_grade' => $gradeId]);
    }
}
